package cs422.project2.testing;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Anosh 
{
	static Statement statement;
	

	public static void main(String args[])
	{
		//Connection conn = null;
		Anosh test = new Anosh();
		
		
	try {
		Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/jmdb","root","admin");
		statement = conn.createStatement();
		System.out.println(conn);
		// Do something with the Connection
		} catch (SQLException ex)
		{
			// handle any errors
			System.out.println("SQLException: " + ex.getMessage());
			System.out.println("SQLState: " + ex.getSQLState());
			System.out.println("VendorError: " + ex.getErrorCode());
		}
	
		test.getByColumnName();
	
	}
	
	//Function to get the values in the specific columns
		public void getByColumnName()
		{
			try
			{
				//Create a Result Set and run a query on it
				ResultSet infoMovie = statement.executeQuery("SELECT * FROM movies where sflag=0");
				//Printing mechanism
				int row=0;
				while(infoMovie.next())
				{
					//Add the specific column names to print the result
					System.out.println("Row "+(++row)+") "+
								   infoMovie.getString("movieid")+" "+
								   infoMovie.getString("title"));
				}
				infoMovie.close(); 
			}
			catch(SQLException ex)
			{
				System.out.println("SQL Exception");
				System.out.println("SQL State "+ ex.getSQLState());
				System.out.println("Message "+ ex.getMessage());
			}
		}
}
